#!/bin/bash

CROSS_COMPILING_PREFIX = CGO_ENABLED=0 GOOS=linux GOARCH=arm64

INSTALL_PATH=bin/
$(shell test -d ${INSTALL_PATH}/linux || mkdir -p ${INSTALL_PATH}/linux)
$(shell test -d ${INSTALL_PATH}/win || mkdir -p ${INSTALL_PATH}/win)


all: communication_tool

# go env
check_path:
	$(info GOPATH=$(GOPATH))
	$(info GOROOT=$(GOROOT))
	$(info GOBIN=$(GOBIN))
	$(info GO111MODULE=$(GO111MODULE))
	$(info GOPROXY=$(GOPROXY))

update:
	go mod tidy


communication_tool:
	go build -mod=mod -o ${INSTALL_PATH}/linux/iot_tool src/communication_tool/main.go
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/iot_tool.exe src/communication_tool/main.go

copy_tool:
	cp ./bin/linux/iot_tool /media/sherlock/d/linux/code/qt/RobotPlatformTool/tool/ubuntu
	cp ./bin/win/iot_tool.exe /media/sherlock/d/linux/code/qt/RobotPlatformTool/tool/win

odom_time_tool:
	go build -mod=mod -o ${INSTALL_PATH}/linux/odom_timestamp_tool src/odom_time/main.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/odom_timestamp_tool src/odom_time/main.go

tool:
	#go build -mod=mod -o ${INSTALL_PATH}/linux/perform_check src/tools/platform_check/platform_check.go
	#CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/perform_check src/tools/platform_check/platform_check.go
	#CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/perform_check.exe src/tools/platform_check/platform_check.go
	go build -mod=mod -o ${INSTALL_PATH}/linux/camera_control src/tools/camera_control/camera_control.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/camera_control src/tools/camera_control/camera_control.go
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/camera_control.exe src/tools/camera_control/camera_control.go
#	go build -mod=mod -o ${INSTALL_PATH}/linux/read_version src/tools/version/read_version.go
#	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/read_version src/tools/version/read_version.go
#	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/read_version.exe src/tools/version/read_version.go
	#CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/mcu_sleep src/tools/mcu_sleep/mcu_sleep.go

temp:
	go build -mod=mod -o ${INSTALL_PATH}/linux/temp src/temp/temp.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/temp src/temp/temp.go

report_data:
	go build -mod=mod -o ${INSTALL_PATH}/linux/report_device src/srv_tool/report_device_data_tool.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/report_device src/srv_tool/report_device_data_tool.go

ota_tool:
	go build -mod=mod -o ${INSTALL_PATH}/linux/ota_tool src/ota/ota_tool.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/ota_tool src/ota/ota_tool.go
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/ota_tool.exe src/ota/ota_tool.go

boolrobotmain_tool:
	go build -mod=mod -o ${INSTALL_PATH}/linux/self_test_cmd src/boolrobotmain/self_test_cmd.go
	go build -mod=mod -o ${INSTALL_PATH}/linux/self_test_str_cmd src/boolrobotmain/self_test_str_cmd.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/self_test_cmd src/boolrobotmain/self_test_cmd.go
	CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -mod=mod -o ${INSTALL_PATH}/arm/self_test_str_cmd src/boolrobotmain/self_test_str_cmd.go
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/self_test_cmd.exe src/boolrobotmain/self_test_cmd.go
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/self_test_str_cmd.exe src/boolrobotmain/self_test_str_cmd.go

ros_bag:
	go build -mod=mod -o ${INSTALL_PATH}/linux/ros_bag src/ros_bag/main.go
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod=mod -o ${INSTALL_PATH}/win/ros_bag.exe src/ros_bag/main.go

clean:
	rm -rf ./bin

.PHONY: all
